import java.util.Scanner;

/**
 * Created with IntelliJ IDEA.
 * Description:    给定一个二维数组，请你编写一个求和函数，计算出这个数组元素的和
 * 输出描述：输出二维数组元素的和
 * User: 86183
 */

public class Test {
    //方法二：采用foreach来遍历
    public static void main(String[] args) {
        int[][]  arr = {{11,33,55},{22,44,66,88},{131,214,315,146},{928,827,726,625},{424,525}};
        int sum=add(arr);
        System.out.println(sum);
    }
    public static int arr(int[][] arr){
        int sum = 0;
        for (int[] arr1: arr ) {
            for (int x: arr1 ) {
                sum += x;
            }
        }
        return sum;
    }
    //方法一：采用for循环来遍历
    public static void main1(String[] args) {
        int[][]  arr = {{11,33,55},{22,44,66,88},{131,214,315,146},{928,827,726,625},{424,525}};
        int sum=add(arr);
        System.out.println(sum);
    }

    public static int add(int[][] arr) {
        int sum=0;
        for( int i = 0; i < arr.length ;i++){//遍历行
            for( int j = 0;j < arr[i].length ;j++){//遍历列
                sum += arr[i][j];
            }
        }

        return sum;
    }
}
